<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>文档 | lowcode</title>
    <meta name="description" content="">
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/assets/logo.png">
    <meta name="description" content="低代码工具">
    <meta name="referrer" content="never">
    <meta name="keywords" content="lowcode">
    <link rel="preload" href="/assets/css/0.styles.9b0a5037.css" as="style"><link rel="preload" href="/assets/js/app.9e4f828f.js" as="script"><link rel="preload" href="/assets/js/2.63a13152.js" as="script"><link rel="preload" href="/assets/js/6.3c92ec7c.js" as="script"><link rel="prefetch" href="/assets/js/10.21256974.js"><link rel="prefetch" href="/assets/js/11.c8692837.js"><link rel="prefetch" href="/assets/js/12.f3273b7c.js"><link rel="prefetch" href="/assets/js/13.4485523d.js"><link rel="prefetch" href="/assets/js/14.b5a376cd.js"><link rel="prefetch" href="/assets/js/15.f3c4584a.js"><link rel="prefetch" href="/assets/js/16.2d7cc251.js"><link rel="prefetch" href="/assets/js/17.8b66ec9b.js"><link rel="prefetch" href="/assets/js/3.cf42858e.js"><link rel="prefetch" href="/assets/js/4.0301f468.js"><link rel="prefetch" href="/assets/js/5.cfdf5b5e.js"><link rel="prefetch" href="/assets/js/7.9cd0ba8d.js"><link rel="prefetch" href="/assets/js/8.71b6f748.js"><link rel="prefetch" href="/assets/js/9.b2f4095e.js">
    <link rel="stylesheet" href="/assets/css/0.styles.9b0a5037.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="ant-row"><div class="nav-button"><i aria-label="icon: bars" class="anticon anticon-bars"><svg viewBox="0 0 1024 1024" focusable="false" data-icon="bars" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M912 192H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 284H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 284H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM104 228a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 284a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 284a56 56 0 1 0 112 0 56 56 0 1 0-112 0z"></path></svg></i> <span></span></div> <div class="ant-col ant-col-xs-24 ant-col-sm-24 ant-col-md-6 ant-col-lg-5 ant-col-xl-5 ant-col-xxl-4"><a href="/" class="router-link-active home-link"><img src="/assets/logo.png" alt="lowcode" class="logo"> <span class="site-name">lowcode</span></a> <div class="search-box mobile-search"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div></div> <div class="ant-col ant-col-xs-0 ant-col-sm-0 ant-col-md-18 ant-col-lg-19 ant-col-xl-19 ant-col-xxl-20"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><ul role="menu" id="nav" class="ant-menu ant-menu-horizontal ant-menu-root ant-menu-light"><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/" class="router-link-active">
          首页
        </a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/lowcode-vscode/">
          lowcode-vscode
        </a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item ant-menu-item-selected"><a href="/lowcode-mock/" aria-current="page" class="router-link-exact-active router-link-active">
          lowcode-mock
        </a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="https://lowcoding.gitee.io/" target="_blank">
          国内镜像
          <i aria-label="icon: link" class="anticon anticon-link"><svg viewBox="64 64 896 896" focusable="false" data-icon="link" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M574 665.4a8.03 8.03 0 0 0-11.3 0L446.5 781.6c-53.8 53.8-144.6 59.5-204 0-59.5-59.5-53.8-150.2 0-204l116.2-116.2c3.1-3.1 3.1-8.2 0-11.3l-39.8-39.8a8.03 8.03 0 0 0-11.3 0L191.4 526.5c-84.6 84.6-84.6 221.5 0 306s221.5 84.6 306 0l116.2-116.2c3.1-3.1 3.1-8.2 0-11.3L574 665.4zm258.6-474c-84.6-84.6-221.5-84.6-306 0L410.3 307.6a8.03 8.03 0 0 0 0 11.3l39.7 39.7c3.1 3.1 8.2 3.1 11.3 0l116.2-116.2c53.8-53.8 144.6-59.5 204 0 59.5 59.5 53.8 150.2 0 204L665.3 562.6a8.03 8.03 0 0 0 0 11.3l39.8 39.8c3.1 3.1 8.2 3.1 11.3 0l116.2-116.2c84.5-84.6 84.5-221.5 0-306.1zM610.1 372.3a8.03 8.03 0 0 0-11.3 0L372.3 598.7a8.03 8.03 0 0 0 0 11.3l39.6 39.6c3.1 3.1 8.2 3.1 11.3 0l226.4-226.4c3.1-3.1 3.1-8.2 0-11.3l-39.5-39.6z"></path></svg></i></a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="visibility:hidden;position:absolute;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li></ul> <a href="https://github.com/lowcoding" target="_blank" rel="noopener noreferrer" class="repo-link"><i aria-label="icon: github" class="anticon anticon-github"><svg viewBox="64 64 896 896" focusable="false" data-icon="github" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M511.6 76.3C264.3 76.2 64 276.4 64 523.5 64 718.9 189.3 885 363.8 946c23.5 5.9 19.9-10.8 19.9-22.2v-77.5c-135.7 15.9-141.2-73.9-150.3-88.9C215 726 171.5 718 184.5 703c30.9-15.9 62.4 4 98.9 57.9 26.4 39.1 77.9 32.5 104 26 5.7-23.5 17.9-44.5 34.7-60.8-140.6-25.2-199.2-111-199.2-213 0-49.5 16.3-95 48.3-131.7-20.4-60.5 1.9-112.3 4.9-120 58.1-5.2 118.5 41.6 123.2 45.3 33-8.9 70.7-13.6 112.9-13.6 42.4 0 80.2 4.9 113.5 13.9 11.3-8.6 67.3-48.8 121.3-43.9 2.9 7.7 24.7 58.3 5.5 118 32.4 36.8 48.9 82.7 48.9 132.3 0 102.2-59 188.1-200 212.9a127.5 127.5 0 0 1 38.1 91v112.5c.8 9 0 17.9 15 17.9 177.1-59.7 304.6-227 304.6-424.1 0-247.2-200.4-447.3-447.5-447.3z"></path></svg></i></a></nav></div></div> <!----></header> <aside class="sidebar"><div><div class="promo"><div id="promo_3"><div class="promo_title">赞助商</div> <button type="button" class="ant-btn ant-btn-primary ant-btn-background-ghost"><span>成为赞助商</span></button></div></div> <div role="separator" id="reset-margin" class="ant-divider ant-divider-horizontal ant-divider-dashed"></div></div> <ul class="sidebar-links"><li><a href="/lowcode-mock/" aria-current="page" title="文档" class="active sidebar-link">文档</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/lowcode-mock/#概述" title="概述" class="sidebar-link">概述</a></li><li class="sidebar-sub-header"><a href="/lowcode-mock/#安装" title="安装" class="sidebar-link">安装</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/lowcode-mock/#install" title="Install" class="sidebar-link">Install</a></li><li class="sidebar-sub-header"><a href="/lowcode-mock/#start" title="Start" class="sidebar-link">Start</a></li></ul></li><li class="sidebar-sub-header"><a href="/lowcode-mock/#mock" title="mock" class="sidebar-link">mock</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/lowcode-mock/#根据-yapi-生成-mock" title="根据 YAPI 生成 mock" class="sidebar-link">根据 YAPI 生成 mock</a></li><li class="sidebar-sub-header"><a href="/lowcode-mock/#根据-json-生成-mock" title="根据 JSON 生成 mock" class="sidebar-link">根据 JSON 生成 mock</a></li><li class="sidebar-sub-header"><a href="/lowcode-mock/#根据字段类型或字段名称生成特定的-mock-数据" title="根据字段类型或字段名称生成特定的 mock 数据" class="sidebar-link">根据字段类型或字段名称生成特定的 mock 数据</a></li></ul></li><li class="sidebar-sub-header"><a href="/lowcode-mock/#延时" title="延时" class="sidebar-link">延时</a></li><li class="sidebar-sub-header"><a href="/lowcode-mock/#http-异常状态码" title="http 异常状态码" class="sidebar-link">http 异常状态码</a></li><li class="sidebar-sub-header"><a href="/lowcode-mock/#代理" title="代理" class="sidebar-link">代理</a></li><li class="sidebar-sub-header"><a href="/lowcode-mock/#拦截响应" title="拦截响应" class="sidebar-link">拦截响应</a></li></ul></li></ul></aside> <main class="page"> <div class="theme-antdocs-content content__default"><h2 id="概述">概述 <a href="#概述" class="header-anchor">#</a></h2> <p>mock &amp; 代理 工具。</p> <p><img src="https://s1.ax1x.com/2020/09/12/wdZFc6.gif" alt="wdZFc6.gif"></p> <p><img src="https://i.loli.net/2020/09/12/BC3vZwXaG1YqOl6.gif" alt="3.gif"></p> <h2 id="安装">安装 <a href="#安装" class="header-anchor">#</a></h2> <h3 id="install">Install <a href="#install" class="header-anchor">#</a></h3> <p><code>yarn create @lowcoding/mock</code></p> <h3 id="start">Start <a href="#start" class="header-anchor">#</a></h3> <p><code>yarn start</code></p> <p>mock server 默认在本地 3000 端口启动，访问 <a href="http://localhost:3000/" target="_blank" rel="noopener noreferrer">http://localhost:3000/<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 即可。</p> <blockquote><p><code>lowcode-mock</code> 默认支持跨域。</p></blockquote> <h2 id="mock">mock <a href="#mock" class="header-anchor">#</a></h2> <p>在 <code>src\routes</code> 目录下新建一个 js 文件，将如下内容复制进去保存即可：</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">import</span> KoaRouter <span class="token keyword">from</span> <span class="token string">&quot;koa-router&quot;</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> proxy <span class="token keyword">from</span> <span class="token string">&quot;../middleware/Proxy&quot;</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> delay <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;../lib/util&quot;</span><span class="token punctuation">;</span>
<span class="token keyword">let</span> Mock <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">&quot;mockjs&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">let</span> Random <span class="token operator">=</span> Mock<span class="token punctuation">.</span>Random<span class="token punctuation">;</span>

<span class="token keyword">const</span> router <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">KoaRouter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
router<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string">&quot;/your-mock-api&quot;</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token parameter">ctx</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
	ctx<span class="token punctuation">.</span>body <span class="token operator">=</span> <span class="token string">&quot;你的第一个mock接口&quot;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
module<span class="token punctuation">.</span>exports <span class="token operator">=</span> router<span class="token punctuation">;</span>
</code></pre></div><blockquote><p>已经内置了创建新 mock 的物料，在 <code>vscode-lowcode</code> 的区块功能中直接使用即可。</p></blockquote> <p>使用 vscode 插件 <a href="https://marketplace.visualstudio.com/items?itemName=wjkang.lowcode" target="_blank" rel="noopener noreferrer">lowcode<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> ，可直接根据 JSON 数据或者 YAPI 接口定义自动生成 mock 接口以及 mock 数据。</p> <h3 id="根据-yapi-生成-mock">根据 YAPI 生成 mock <a href="#根据-yapi-生成-mock" class="header-anchor">#</a></h3> <blockquote><p>如何配置 <code>vscode-lowcode</code>，查看 <a href="https://lowcoding.gitee.io/lowcode-vscode/config.html" target="_blank" rel="noopener noreferrer">文档<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p></blockquote> <p>复制 YAPI 上接口 id ，比如 <code>https://yapi.baidu.com/project/869/interface/api/14037</code> 最后面的数字部分</p> <p><img src="https://s1.ax1x.com/2020/09/12/wdZFc6.gif" alt="wdZFc6.gif"></p> <h3 id="根据-json-生成-mock">根据 JSON 生成 mock <a href="#根据-json-生成-mock" class="header-anchor">#</a></h3> <p>复制 JSON 数据，比如：</p> <p><img src="https://i.loli.net/2020/09/12/BC3vZwXaG1YqOl6.gif" alt="3.gif"></p> <blockquote><p>通过 JSON 数据生成的 mock 接口需要手动修改路由地址。</p></blockquote> <h3 id="根据字段类型或字段名称生成特定的-mock-数据">根据字段类型或字段名称生成特定的 mock 数据 <a href="#根据字段类型或字段名称生成特定的-mock-数据" class="header-anchor">#</a></h3> <p>如下为默认的，按需要自行配置即可</p> <p><img src="https://fastly.jsdelivr.net/gh/migrate-gitee/img-host@latest/2020/11/12/1605111557350.png" alt=""></p> <blockquote><p><code>200&amp;&amp;number</code> 一处表示当需要 mock 的字段名为<code>code</code>，并且类型为<code>number</code>，mock 为固定值 200</p></blockquote> <h2 id="延时">延时 <a href="#延时" class="header-anchor">#</a></h2> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">import</span> KoaRouter <span class="token keyword">from</span> <span class="token string">&quot;koa-router&quot;</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> proxy <span class="token keyword">from</span> <span class="token string">&quot;../middleware/Proxy&quot;</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> delay <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;../lib/util&quot;</span><span class="token punctuation">;</span>
<span class="token keyword">let</span> Mock <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">&quot;mockjs&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">let</span> Random <span class="token operator">=</span> Mock<span class="token punctuation">.</span>Random<span class="token punctuation">;</span>

<span class="token keyword">const</span> router <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">KoaRouter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
router<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string">&quot;/delay&quot;</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token parameter">ctx</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
	<span class="token function">delay</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 3 秒后返回结果</span>
	ctx<span class="token punctuation">.</span>body <span class="token operator">=</span> <span class="token string">&quot;delay&quot;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><blockquote><p>可用于测 loading 效果。</p></blockquote> <h2 id="http-异常状态码">http 异常状态码 <a href="#http-异常状态码" class="header-anchor">#</a></h2> <div class="language-js extra-class"><pre class="language-js"><code>router<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string">&quot;/httpError&quot;</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token parameter">ctx</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
	ctx<span class="token punctuation">.</span>status <span class="token operator">=</span> <span class="token number">401</span><span class="token punctuation">;</span>
	ctx<span class="token punctuation">.</span>body <span class="token operator">=</span> <span class="token string">&quot;http 401&quot;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h2 id="代理">代理 <a href="#代理" class="header-anchor">#</a></h2> <div class="language-js extra-class"><pre class="language-js"><code>router<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string">&quot;/proxy&quot;</span><span class="token punctuation">,</span> <span class="token function">proxy</span><span class="token punctuation">(</span><span class="token string">&quot;https://github.com/wjkang/lowcode-mock&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token parameter">ctx</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
	ctx<span class="token punctuation">.</span>body <span class="token operator">=</span> <span class="token string">&quot;https://github.com/wjkang/lowcode-mock&quot;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><blockquote><p>来自 <code>/proxy</code> 的请求转发到 <code>https://github.com/wjkang/lowcode-mock/proxy</code> ，用于后端接口可联调的时候跳过本地 mock，转发请求到后端接口。</p></blockquote> <div class="language-js extra-class"><pre class="language-js"><code>router<span class="token punctuation">.</span><span class="token function">all</span><span class="token punctuation">(</span>
	<span class="token keyword">new</span> <span class="token class-name">RegExp</span><span class="token punctuation">(</span><span class="token string">&quot;^/lowcode/mock/(|^$)&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
	<span class="token function">proxy</span><span class="token punctuation">(</span><span class="token string">&quot;https://github.com/wjkang/lowcode-mock&quot;</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><blockquote><p>不需要 mock 并且匹配正则的接口直接转发到后端地址。</p></blockquote> <h2 id="拦截响应">拦截响应 <a href="#拦截响应" class="header-anchor">#</a></h2> <div class="language-js extra-class"><pre class="language-js"><code><span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string">'/intercept/response'</span><span class="token punctuation">,</span> <span class="token keyword">async</span> <span class="token punctuation">(</span><span class="token parameter">ctx</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
		<span class="token keyword">const</span> result <span class="token operator">=</span> <span class="token keyword">await</span> <span class="token function">request</span><span class="token punctuation">(</span>ctx<span class="token punctuation">,</span> <span class="token string">'http://localhost:3000/mock'</span><span class="token punctuation">)</span>
		<span class="token keyword">const</span> interceptResult <span class="token operator">=</span> <span class="token punctuation">{</span>
			<span class="token operator">...</span>result<span class="token punctuation">.</span>body<span class="token punctuation">,</span>
			<span class="token literal-property property">intercept</span><span class="token operator">:</span> <span class="token string">'拦截相应'</span><span class="token punctuation">,</span>
		<span class="token punctuation">}</span>
		ctx<span class="token punctuation">.</span>body <span class="token operator">=</span> interceptResult
	<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre></div><blockquote><p>可用于 mock 现有接口新增字段</p></blockquote></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">5/21/2022, 8:45:47 AM</span></div></footer> <!----> </main> <!----></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.9e4f828f.js" defer></script><script src="/assets/js/2.63a13152.js" defer></script><script src="/assets/js/6.3c92ec7c.js" defer></script>
  </body>
</html>